package utils;

import java.io.IOException;
import java.net.Socket;

/**
 * @author zhuyaokunll@foxmail.com
 * @date 2018/7/30 15:30
 */
public class ServerSocket {
    private static java.net.ServerSocket serverSocket;
    private static int index=1;

    public static void waiteClient(){
        try {
            serverSocket = new java.net.ServerSocket(50030);
            //通过ServerSocket不断监听端口50030，每来一个一个客户端，新建一个SocketHandleThread对象来处理
            while(true){
                Socket socket = null;
                Log4jInit.logger.info("开始监听端口：50030");
                socket = serverSocket.accept();
                //当监听到了客户端连接后，创建新线程传输数据，这样可以实现多个客户端同时访问
                new SocketHandleThread(socket,index++).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Log4jInit.logger.info("监听端口失败：50030");
        }
    }
}
